package cn.myframe.controller.bus;

import java.util.Map;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.myframe.controller.AbstractController;
import cn.myframe.controller.BaseController;
import cn.myframe.service.BaseService;
import cn.myframe.utils.annotation.CheckDelete;
import cn.myframe.utils.annotation.CheckNoPass;
import cn.myframe.utils.aop.AssociateData;
import cn.myframe.utils.core.R;
import cn.myframe.entity.bus.BusRegionEntity;
import cn.myframe.service.bus.BusRegionService;


/**
 * 区域管理
 * 
 * @author ynz
 * @email ynz@myframe.cn
 * @date 2018-08-24 10:51:02
 */
@RestController
@RequestMapping("/bus/busregion")
public class BusRegionController  extends AbstractController implements BaseController<BusRegionEntity,BaseService<BusRegionEntity>>{
	@Autowired
	private BusRegionService busRegionService;
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping(value = "/list",method = {RequestMethod.GET})
	@RequiresPermissions("busregion:list")
	public R list(@RequestParam Map<String, Object> params){
		return this.defaultList(params);
	}	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("busregion:info")
	public R info(@PathVariable("id") Long id){
		return this.defaultInfo(id,"busRegion");
	}
	
	/**
	 * 新增保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("busregion:save")
	public R save(@RequestBody BusRegionEntity busRegion){		
		return this.defaultSave(busRegion);
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("busregion:delete")
	@CheckDelete(AssociateData.COMPANY_REGION+","+AssociateData.GROUP_REGION+","+AssociateData.SMARAT_REGION)
	public R delete(@RequestBody Long[] ids){		
		return this.defaultDelete(ids);
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")	
	@RequiresPermissions("busregion:update")
	public R update(@RequestBody BusRegionEntity busRegion){		
		return this.defaultUpdate(busRegion);
	}
	
   /**
    * 提交,审核
    */
	@RequestMapping("/audit")	
	@RequiresPermissions(value={"busregion:submit","busregion:auditpass","busregion:auditnopass"},logical=Logical.OR)
	@CheckNoPass(AssociateData.SMARAT_REGION+","+AssociateData.COMPANY_REGION
			+","+AssociateData.GROUP_REGION)
	public R audit(@RequestBody Long[] ids ,@RequestParam Integer status){
		return this.defaultAudit(ids, status);
	}
	
   /**
	* 检验字段值重复
	*/
    @RequestMapping("/checkExist")
    @ResponseBody
    public String checkExist(String id,String value,String columnName){
        return this.defaultCheckExist(id, value, columnName);
    }
    
    @RequestMapping("/findone/{id}")
	public R findOne(@PathVariable("id") Integer id){
		BusRegionEntity area = busRegionService.queryObject(id);
		
		return R.ok().put("area", area);
	}
    
    public BusRegionService getService(){
		return busRegionService;
	}
	
}
